<?php
class Cerad_Url
{
	protected $context = NULL;
	protected $prefix;
	protected $script = 'index.php';
	
	function __construct($context)
	{
		$this->context = $context;
		
		$request = $context->getRequest();
		
		// For now just generate the prefix directly
		$appWebDir = dirname($request->getServer('SCRIPT_NAME'));
		
		/* Server name is often handy */
		$appServerName = $request->getServer('SERVER_NAME');
		
		/* Absolute url */
		$this->prefix = "http://{$appServerName}{$appWebDir}";
	}
	function link($actionClassName,$input = NULL)
	{
		$actionIndex = $this->context->getRoutes()->getActionClassIndex($actionClassName);
		$params = array('a' => $actionIndex);
		if ($input) {
			if (is_array($input)) $params = array_merge($params,$input);
			else $params['id'] = $input;
		}
		$query = http_build_query($params,NULL,'&'); // Need to research a bit
		$link = $this->prefix . '/' . $this->script . '?' . $query;
		
		return $link;
		
	}
}
?>